package com.example.app.base

import android.os.Bundle
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import com.example.app.R
import com.example.app.dialog.CommonLoadingDialog
import com.gyf.immersionbar.ImmersionBar
import com.lxj.xpopup.core.BasePopupView
import com.weikaiyun.fragmentation.SupportActivity

/**
 * CreateBy:Joker
 * CreateTime:2024/8/19 11:43
 * description：
 */
abstract class BaseActivity : SupportActivity() {

    abstract fun getLogTag(): String

    var statusBarHigh = 0
    private var loadingDialog: BasePopupView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        statusBarHigh = ImmersionBar.getStatusBarHeight(this)
        LogUtils.dTag(getLogTag(),"onCreate statusBarHigh=${statusBarHigh}")
        ImmersionBar.with(this).statusBarDarkFont(true).init()
        ScreenUtils.setNonFullScreen(this)
        BarUtils.setNavBarLightMode(this, true)
        BarUtils.setNavBarColor(this, ColorUtils.getColor(R.color.color_white))
    }

    override fun onRestart() {
        super.onRestart()
        LogUtils.i("${getLogTag()},onRestart")
    }

    override fun onResume() {
        super.onResume()
        LogUtils.i("${getLogTag()},onResume")
    }

    override fun onPause() {
        super.onPause()
        LogUtils.d("${getLogTag()},onPause")
    }

    override fun onStop() {
        super.onStop()
        LogUtils.i("${getLogTag()},onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        LogUtils.i("${getLogTag()},onDestroy")
    }

    /** 显示加载框 */
    fun showLoadingDialog(isCancelTouchOutSide: Boolean = true) {
        if (loadingDialog?.isShow == true) return

        loadingDialog = CommonLoadingDialog.show(this, isCancelTouchOutSide)
    }

    /** 关闭加载框 */
    fun dismissLoadingDialog() {
        loadingDialog?.dismiss()
        loadingDialog = null
    }

    fun setStatusBarDarkFont(isDark: Boolean) {
        ImmersionBar.with(this).statusBarDarkFont(isDark).navigationBarColor(R.color.color_white).init()
    }

}